//
//  HomeQuestionSliderProgessView.m
//  ZJControlsClass
//
//  Created by mac on 2024/11/23.
//

#import "HomeQuestionSliderProgessView.h"
#import "HomeQustionProgessNumberCollectionViewCell.h"




@interface HomeQuestionSliderProgessView ()<UICollectionViewDelegate,UICollectionViewDataSource>



@property (nonatomic,strong) UIButton * dismissBtn;
@property (nonatomic,strong) UILabel * titleLabel;
@property (nonatomic,strong) UICollectionView * collectionView;
@property (nonatomic,strong) NSMutableArray * datSource;
@property (nonatomic,strong) UIButton * canleBtn;
@property (nonatomic,strong) UIButton * sureBtn;

@end



@implementation HomeQuestionSliderProgessView

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self){
        
        self.backgroundColor = [UIColor whiteColor];
        
        [self configUI];
        
        
        
    }
    return self;
    
}


-(void)configUI{
    
    [self addSubview:self.dismissBtn];
    [self addSubview:self.titleLabel];
    [self addSubview:self.collectionView];
    [self addSubview:self.canleBtn];
    [self addSubview:self.sureBtn];
    
    
    
    [self.dismissBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).with.offset(-ALIGN_WIDTH_PT(12));
        make.top.equalTo(self).with.offset(ALIGN_HEIGHT_PT(15));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(22), ALIGN_WIDTH_PT(22))));
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).with.offset(ALIGN_HEIGHT_PT(30));
        make.left.right.equalTo(self);
    }];
    
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).with.offset(ALIGN_WIDTH_PT(12));
        make.right.equalTo(self).with.offset(-ALIGN_WIDTH_PT(12));
        make.top.equalTo(self.titleLabel.mas_bottom).with.offset(ALIGN_HEIGHT_PT(20));
        make.height.equalTo(@(ALIGN_HEIGHT_PT(190)));
    }];
    
    [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).with.offset(-ALIGN_WIDTH_PT(12));
        make.top.equalTo(self.collectionView.mas_bottom).with.offset(ALIGN_HEIGHT_PT(40));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(102), ALIGN_HEIGHT_PT(44))));
    }];
    
    
    
    [self.canleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.sureBtn.mas_left).with.offset(-ALIGN_WIDTH_PT(12));
        make.centerY.equalTo(self.sureBtn.mas_centerY);
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(102), ALIGN_HEIGHT_PT(44))));
    }];
    
    
    
}


#pragma mark -- 点击事件
-(void)respondsTo_dissmissBtn{
    _block();
}



#pragma mark -- UICollectionViewDelegate,UICollectionViewDataSource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
//    return [self.dataSource count];
    return self.totalNum;
}
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    HomeQustionProgessNumberCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeQustionProgessNumberCollectionViewCell" forIndexPath:indexPath];
//    HomeQuestionModel * model = self.dataSource[indexPath.row];
//    cell.model = model;
    
    cell.numberLabel.text = [NSString stringWithFormat:@"%@",@(indexPath.row + 1)];
    if (indexPath.row + 1 < self.chooseNum){
    
        cell.follewView.backgroundColor = COLOR_RGB(224, 233, 251);
        cell.numberLabel.textColor = COLOR_RGB(50, 113, 237);
        
    }else if (indexPath.row + 1 == self.chooseNum){
        
        cell.follewView.backgroundColor =  COLOR_RGB(50, 113, 237);
        cell.numberLabel.textColor = [UIColor whiteColor];
        
    }else{
        
        cell.follewView.backgroundColor =  COLOR_RGB(244, 244, 244);
        cell.numberLabel.textColor = COLOR_RGB(180, 180, 180);
    }
    
    return cell;
    
    
    
}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    
}
 /* 头部视图 */
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    UICollectionReusableView * reusableView = nil;

    
    return  reusableView;
}

/* 头部试图高度 */
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(nonnull UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    if (section != 0) return CGSizeMake(SCREEN_WIDTH, ALIGN_HEIGHT_PT(40));
    return CGSizeMake(0, 0);
}



#pragma mark - item宽高
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
   
    return CGSizeMake((SCREEN_WIDTH - ALIGN_WIDTH_PT(48)) / 5, ALIGN_HEIGHT_PT(28));

    
}

#pragma mark - <UICollectionViewDelegateFlowLayout>
#pragma mark - X间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return  ALIGN_WIDTH_PT(6);
}
#pragma mark - Y间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return  ALIGN_WIDTH_PT(10);
}




#pragma mark -- 懒加载
-(UIButton *)dismissBtn{
    if (!_dismissBtn){
        _dismissBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [_dismissBtn setImage:[UIImage imageNamed:@"dissmiss"] forState:(UIControlStateNormal)];
        [_dismissBtn addTarget:self action:@selector(respondsTo_dissmissBtn) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _dismissBtn;
}

-(UILabel *)titleLabel{
    if (!_titleLabel){
        _titleLabel = [UILabel new];
        _titleLabel.text = @"进度详情";
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = [UIFont systemFontOfSize:22 weight:0.5];
        _titleLabel.textColor = [UIColor blackColor];
    }
    return _titleLabel;
}

-(UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
        layout.minimumLineSpacing = 0;
        layout.minimumInteritemSpacing = 0;
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor clearColor];
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        //cell
        [_collectionView registerClass:[HomeQustionProgessNumberCollectionViewCell class] forCellWithReuseIdentifier:@"HomeQustionProgessNumberCollectionViewCell"];

    }
    return _collectionView;
}

-(UIButton *)canleBtn{
    if (!_canleBtn){
        _canleBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_canleBtn setTitle:@"取消" forState:(UIControlStateNormal)];
        _canleBtn.titleLabel.font = FONT15;
        [_canleBtn setTitleColor:COLOR_RGB(50, 113, 237) forState:(UIControlStateNormal)];
        _canleBtn.layer.cornerRadius = 6;
        _canleBtn.layer.masksToBounds = YES;
        _canleBtn.layer.borderColor = COLOR_RGB(50, 113, 237).CGColor;
        _canleBtn.layer.borderWidth = 1;
        _canleBtn.backgroundColor = [UIColor whiteColor];
    }
    return _canleBtn;
}

-(UIButton *)sureBtn{
    if (!_sureBtn){
        _sureBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_sureBtn setTitle:@"确认" forState:(UIControlStateNormal)];
        _sureBtn.titleLabel.font = FONT15;
        [_sureBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        _sureBtn.layer.cornerRadius = 6;
        _sureBtn.layer.masksToBounds = YES;
        _sureBtn.backgroundColor = COLOR_RGB(50, 113, 237);
    }
    return _sureBtn;
}





@end
